# download SPIRV-Cross (Apache-2.0 license)

if (FALSE)
	set( FG_EXTERNAL_SPIRV_CROSS_PATH "" CACHE PATH "path to SPIRV-Cross source" )
	mark_as_advanced( FG_EXTERNAL_SPIRV_CROSS_PATH )

	# reset to default
	if (NOT EXISTS "${FG_EXTERNAL_SPIRV_CROSS_PATH}/spirv_cross.hpp")
		message( STATUS "SPIRV-Cross is not found in \"${FG_EXTERNAL_SPIRV_CROSS_PATH}\"" )
		set( FG_EXTERNAL_SPIRV_CROSS_PATH "${FG_EXTERNALS_PATH}/SPIRV-Cross" CACHE PATH "" FORCE )
	else ()
		message( STATUS "SPIRV-Cross found in \"${FG_EXTERNAL_SPIRV_CROSS_PATH}\"" )
	endif ()

	# select version
	if (${FG_EXTERNALS_USE_STABLE_VERSIONS})
		set( SPIRVCROSS_TAG "2019-11-01" )
	else ()
		set( SPIRVCROSS_TAG "master" )
	endif ()
	
	set( FG_SPIRV_CROSS_INSTALL_DIR "${FG_EXTERNALS_INSTALL_PATH}/SPIRV-Cross" )

	ExternalProject_Add( "External.SPIRV-Cross"
		LOG_OUTPUT_ON_FAILURE 1
        LIST_SEPARATOR		"${FG_LIST_SEPARATOR}"
		# download
		GIT_REPOSITORY		"https://github.com/KhronosGroup/SPIRV-Cross.git"
		GIT_TAG				${SPIRVCROSS_TAG}
		GIT_PROGRESS		1
		# update
		PATCH_COMMAND		""
		UPDATE_DISCONNECTED	1
		# configure
        SOURCE_DIR			"${FG_EXTERNAL_SPIRV_CROSS_PATH}"
		CMAKE_GENERATOR		"${CMAKE_GENERATOR}"
		CMAKE_GENERATOR_PLATFORM "${CMAKE_GENERATOR_PLATFORM}"
		CMAKE_GENERATOR_TOOLSET	"${CMAKE_GENERATOR_TOOLSET}"
		CMAKE_ARGS			"-DCMAKE_CONFIGURATION_TYPES=${CMAKE_BUILD_TYPE}"
							"-DCMAKE_SYSTEM_VERSION=${CMAKE_SYSTEM_VERSION}"
							"-DCMAKE_INSTALL_PREFIX=${FG_SPIRV_CROSS_INSTALL_DIR}"
							"-DSPIRV_CROSS_EXCEPTIONS_TO_ASSERTIONS=ON"
							${FG_BUILD_TARGET_FLAGS}
		LOG_CONFIGURE 		1
		# build
		BINARY_DIR			"${CMAKE_BINARY_DIR}/build-SPIRV-Cross"
		BUILD_COMMAND		"${CMAKE_COMMAND}"
							--build .
							--config $<CONFIG>
		LOG_BUILD 			1
		# install
		INSTALL_DIR 		"${FG_SPIRV_CROSS_INSTALL_DIR}"
		LOG_INSTALL 		1
		# test
		TEST_COMMAND		""
	)
	set_property( TARGET "External.SPIRV-Cross" PROPERTY FOLDER "External" )

	add_library( "SPIRV-Cross-lib" INTERFACE )
	target_include_directories( "SPIRV-Cross-lib" INTERFACE "${FG_EXTERNAL_SPIRV_CROSS_PATH}" )
	target_compile_definitions( "SPIRV-Cross-lib" INTERFACE FG_ENABLE_SPIRV_CROSS )

	set_property( TARGET "SPIRV-Cross-lib" PROPERTY INTERFACE_LINK_LIBRARIES
		"$<$<CONFIG:Debug>:${FG_SPIRV_CROSS_INSTALL_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}spirv-cross-cored${CMAKE_STATIC_LIBRARY_SUFFIX}>"
		"$<$<CONFIG:Debug>:${FG_SPIRV_CROSS_INSTALL_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}spirv-cross-glsld${CMAKE_STATIC_LIBRARY_SUFFIX}>"
		"$<$<CONFIG:Debug>:${FG_SPIRV_CROSS_INSTALL_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}spirv-cross-msld${CMAKE_STATIC_LIBRARY_SUFFIX}>"

		"$<$<CONFIG:Profile>:${FG_SPIRV_CROSS_INSTALL_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}spirv-cross-core${CMAKE_STATIC_LIBRARY_SUFFIX}>"
		"$<$<CONFIG:Profile>:${FG_SPIRV_CROSS_INSTALL_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}spirv-cross-glsl${CMAKE_STATIC_LIBRARY_SUFFIX}>"
		"$<$<CONFIG:Profile>:${FG_SPIRV_CROSS_INSTALL_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}spirv-cross-msl${CMAKE_STATIC_LIBRARY_SUFFIX}>"

		"$<$<CONFIG:Release>:${FG_SPIRV_CROSS_INSTALL_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}spirv-cross-core${CMAKE_STATIC_LIBRARY_SUFFIX}>"
		"$<$<CONFIG:Release>:${FG_SPIRV_CROSS_INSTALL_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}spirv-cross-glsl${CMAKE_STATIC_LIBRARY_SUFFIX}>"
		"$<$<CONFIG:Release>:${FG_SPIRV_CROSS_INSTALL_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}spirv-cross-msl${CMAKE_STATIC_LIBRARY_SUFFIX}>"  )

	add_dependencies( "SPIRV-Cross-lib" "External.SPIRV-Cross" )
endif ()
